package com.itheima.mp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.itheima.mp.others.annotation.NotEmpty;
import com.itheima.mp.others.annotation.Valid;
import com.itheima.mp.others.tools.CommonResult;
import com.itheima.mp.param.*;
import com.itheima.mp.service.SysConfigurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;

@Api(tags = "系统配置信息")
@RestController
@RequestMapping("/sys/configuration")
@Validated
public class SysConfigurationController {

    @Resource
    private SysConfigurationService sysConfigurationService;

    /**
     * 系统配置信息分页
     * @param sysConfigurationPageParam
     * @return
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("系统配置信息分页")
    @GetMapping("/page")
    public CommonResult<Page<SysConfiguration>> page(SysConfigurationPageParam sysConfigurationPageParam) {
        return CommonResult.data(sysConfigurationService.page(sysConfigurationPageParam));
    }


    /**
     * 编辑配置信息
     *
     * @author 01
     * @date 2024/05/31 11:08
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑配置信息")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid SysConfigurationEditParam sysConfigurationEditParam) {
        sysConfigurationService.edit(sysConfigurationEditParam);
        return CommonResult.ok();
    }

    /**
     * 添加系统配置信息
     *
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加系统配置信息")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid SysConfigurationAddParam sysConfigurationAddParam) {
        sysConfigurationService.add(sysConfigurationAddParam);
        return CommonResult.ok();
    }

    /**
     * 获取系统配置详情 6
     *
     * @param sysConfigurationParam
     * @return
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("获取系统配置详情")
    @GetMapping("/detail")
    public CommonResult<SysConfiguration> detail(@Valid SysConfigurationParam sysConfigurationParam) {
        return CommonResult.data(sysConfigurationService.detail(sysConfigurationParam));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("删除内设数据")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                       CommonValidList<SysConfigurationIdParam> sysConfigurationIdParamList) {
        sysConfigurationService.delete(sysConfigurationIdParamList);
        return CommonResult.ok();
    }
}